<template>
  <div class="gstc-component" ref="gstc" :key="1"></div>
</template>

<script>
import GSTC from 'gantt-schedule-timeline-calendar';
import 'gantt-schedule-timeline-calendar/dist/style.css';

let state1,
  gstc,
  loaded = false;

export { GSTC };

export default {
  name: 'GSTC',
  props: ['config'],
  mounted() {
    this.$refs.gstc.addEventListener('gstc-loaded', () => {
      if (!loaded) {
        loaded = true;
        this.$emit('loaded', gstc);
      }
    });
    state1 = GSTC.api.stateFromConfig({});
    this.$watch(
      'config',
      (config) => {
        state1.update('config', (current) => {
          const cfg = GSTC.api.merge({}, current, config);
          return cfg;
        });
        if (gstc && gstc.component) gstc.component.update();
      },
      { deep: true, immediate: true }
    );
    this.$emit('state1', state1);
    gstc = GSTC({
      element: this.$refs.gstc,
      state: state1,
    });
  },
  beforeUnmount() {
    if (gstc) gstc.destroy();
  },
};
</script>
<style scoped>
.gstc-component {
  margin: 0;
  padding: 0;
  height: 1000px;
}
.gstc__list-column-rows--nodeName{
 height: 600px;
}
</style>
